<?php
class Zend_View_Helper_Vista extends Zend_View_Helper_Abstract
{
	private $_config;
	
	const MAGAZINE_TYPE_ID = 1;
	public function vista()
	{
		$this->_config = Zend_Registry::get('config');
		return $this;
	}

	public function getStickyMagazineFront()
	{
		$node = new Cms_Models_Node();
		$rowset = $node->fetchAll(
			$node->select()
			->where('content_type_id = ?', self::MAGAZINE_TYPE_ID )
			->where( "sticky = '1'" )
			->where( "published='1'" )
			->where( "page_front='1'" )
			->where( "locked = 'F'" )
			->limit(3)
		);
		
		if( count($rowset)){
			$items = $rowset->toArray();
		} else {
			$items = array();
		}
		
		$this->view->theme()->render(
			'sticky.tpl.php', 
			array(
				'items'=> $items,
				'view' => $this->view 
			)
		);
	}

	public function getMagazineFront()
	{
		$node = new Cms_Models_Node();
		$rowset = $node->fetchAll(
			$node->select()
			->where('content_type_id = ?', self::MAGAZINE_TYPE_ID )
			->where( "published='1'" )
			->where( "page_front='1'" )
			->where( "locked = 'F'" )
		);
		
		if( count($rowset)){
			$items = $rowset->toArray();
		} else {
			$items = array();
		}
		
		$this->view->theme()->render(
			'regular_content.tpl.php', 
			array(
				'items'=> $items,
				'view' => $this->view 
			)
		);
	}

	public function getMagazineCategory( $tid )
	{
		$node = new Cms_Models_Node();
		$rowset = $node->getAdapter()->fetchAll(
			$node->getAdapter()
				->select()
				->from( array( 'nt' => 'cms_node_taxonomy' ), array() )
				->join( array( 'no' => 'cms_node' ), 'no.node_id = nt.node_id', array('*') )
				->where('content_type_id = ?', self::MAGAZINE_TYPE_ID )
				->where( "published='1'" )
				->where( "locked = 'F'")
				->where( "nt.taxonomy_id = ?", $tid )
		);
		$this->view->theme()->render(
			'regular_content.tpl.php', 
			array(
				'items' => $rowset,
				'view' => $this->view 
			)
		);
	}

	public function getStickyMagazineCategory( $tid )
	{

		$node = new Cms_Models_Node();
		$rowset = $node->getAdapter()->fetchAll(
			$node->getAdapter()
				->select()
				->from( array( 'nt' => 'cms_node_taxonomy' ), array() )
				->join( array( 'no' => 'cms_node' ), 'no.node_id = nt.node_id', array('*') )
				->where('content_type_id = ?', self::MAGAZINE_TYPE_ID )
				->where( "sticky = '1' " )
				->where( "published='1'" )
				->where( "locked = 'F'")
				->where( "nt.taxonomy_id = ?", $tid )
				->limit(3)
		);

		$this->view->theme()->render(
			'sticky.tpl.php', 
			array(
				'items'=> $rowset,
				'view' => $this->view 
			)
		);
	}
}